package com.newtouch.bxzs.business.message.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.newtouch.bxzs.business.config.MyLog;
import com.newtouch.bxzs.business.message.model.NotificationBO;
import com.newtouch.bxzs.business.message.model.NotificationVO;
import com.newtouch.bxzs.business.message.model.bo.*;
import com.newtouch.bxzs.business.message.model.vo.ChangeNotificationStatusVO;
import com.newtouch.bxzs.business.message.model.vo.GetNotificationListVO;
import com.newtouch.bxzs.business.message.model.vo.GetServiceNotificationListVO;
import com.newtouch.bxzs.business.message.service.NotificationService;
import com.newtouch.bxzs.common.base.response.BaseResponse;
import com.newtouch.bxzs.common.base.response.RespGenerator;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 通知信息管理控制类
 *
 * <p>
 * <b>History:</b>
 * <table border="1">
 * <tr>
 * <th>Date</th>
 * <th>Operator</th>
 * <th>Memo</th>
 * </tr>
 * <tr>
 * <td>2020/12/22</td>
 * <td>liman</td>
 * <td>Create</td>
 * </tr>
 * </table>
 *
 * @author liman
 * @version 1.0.0
 * @since 1.0.0
 */
@Api(tags = "维护通知")
@RestController
@RequestMapping("/notificationController")
@SuppressWarnings("unchecked")
public class NotificationController {
    /**
     * 静态变量：系统日志
     */
    private static final Log logger = LogFactory.getLog(NotificationController.class);
    @Autowired
    NotificationService notificationService;

    @ApiOperation(value = "PC端根据查询条件获取通知信息列表")
    @PostMapping("/getNotificationList")
    @MyLog(systemFunctionName = "维护通知", systemFunctionUrl = "/notificationController/getNotificationList", userOperationType = 4, userOperationSummary = "PC端获取通知列表")
    public BaseResponse<IPage<NotificationBO>> getNotificationList(@RequestBody GetNotificationListVO getNotificationListVO) {
        logger.info("查询通知列表");
        IPage<NotificationBO> result = notificationService.getPcNotificationList(getNotificationListVO);
        if (result.getTotal() == 0) {
            return RespGenerator.returnOK("没有查询到相应数据");
        }
        return RespGenerator.returnOK(result);
    }

    @ApiOperation(value = "APP端获取通知列表(通知类型：1-公司通知；3-系统通知；4-个人通知；)")
    @PostMapping("/getAppNotificationList")
    @MyLog(systemFunctionName = "维护通知", systemFunctionUrl = "/notificationController/getAppNotificationList",
            userOperationType = 4, userOperationSummary = "App端查询通知列表")
    public BaseResponse<AppNotificationBO> getAppNotificationList(@RequestBody GetNotificationListVO getNotificationListVO) {
        logger.info("App端查询通知列表");
        return RespGenerator.returnOK(notificationService.getAppNotificationList(getNotificationListVO));
    }

    @ApiOperation(value = "App端获取业务通知的子类型及未读数(通知类型：2-业务通知)")
    @PostMapping("/getAppServiceNotificationTypeList")
    @MyLog(systemFunctionName = "维护通知", systemFunctionUrl = "/notificationController/getAppServiceNotificationTypeList", userOperationType = 4, userOperationSummary = "App端查询业务通知的子类型及未读数")
    public BaseResponse<List<AppServiceNotifyTypeListBO>> getAppServiceNotificationTypeList() {
        logger.info("App端查询业务通知的子类型及未读数(通知类型：2-业务通知)");
        return RespGenerator.returnOK(notificationService.getAppServiceNotificationTypeList());
    }

    @ApiOperation(value = "App端获取业务通知列表")
    @PostMapping("/getAppServiceNotificationList")
    @MyLog(systemFunctionName = "维护通知", systemFunctionUrl = "/notificationController/getAppServiceNotificationList", userOperationType = 4, userOperationSummary = "App端获取业务通知列表")
    public BaseResponse<IPage<AppNotificationListBO>> getAppServiceNotificationList(@RequestBody GetServiceNotificationListVO vo) {
        logger.info("App端获取业务通知列表");
        return RespGenerator.returnOK(notificationService.getAppServiceNotificationList(vo));
    }

    @ApiOperation(value = "PC端根据通知id获取通知信息详情")
    @GetMapping("/getPcNotificationDetail")
    @MyLog(systemFunctionName = "维护通知", systemFunctionUrl = "/notificationController/getPcNotificationDetail", userOperationType = 4, userOperationSummary = "PC端获取通知详情")
    public BaseResponse<NotificationDetailBO> getPcNotificationDetail(@RequestParam @ApiParam(value = "通知id", required = true) String notificationId) {
        logger.info("PC端根据通知编号获取通知信息详情");
        return RespGenerator.returnOK(notificationService.getPcNotificationDetail(notificationId));
    }

    @ApiOperation(value = "App端根据通知id获取通知信息详情")
    @GetMapping("/getAppNotificationDetail")
    @MyLog(systemFunctionName = "维护通知", systemFunctionUrl = "/notificationController/getAppNotificationDetail", userOperationType = 4, userOperationSummary = "App端获取通知详情")
    public BaseResponse<AppNotificationDetailBO> getAppNotificationDetail(@RequestParam @ApiParam(value = "通知id", required = true) String notificationId) {
        logger.info("App端根据通知id获取通知信息详情");
        return RespGenerator.returnOK(notificationService.getAppNotificationDetail(notificationId));
    }

    @ApiOperation(value = "PC端根据通知id逻辑删除通知信息")
    @PostMapping("/deleteNotification")
    @MyLog(systemFunctionName = "维护通知", systemFunctionUrl = "/notificationController/deleteNotification",
            userOperationType = 3, userOperationSummary = "PC端删除通知")
    public BaseResponse<String> deleteNotification(@RequestBody @ApiParam(value = "通知编号", required = true) List<String> notificationIdList) {
        logger.info("PC端根据通知编号逻辑删除通知信息");
        notificationService.deleteNotification(notificationIdList);
        return RespGenerator.returnOK("删除成功");
    }

    @ApiOperation(value = "PC端新增/修改通知信息")
    @PostMapping("/modifyNotification")
    @MyLog(systemFunctionName = "维护通知", systemFunctionUrl = "/notificationController/modifyNotification", userOperationType = 5, userOperationSummary = "PC端新增/修改通知")
    public BaseResponse<String> modifyNotification(@RequestBody NotificationVO notificationVO) {
        logger.info("PC端端新增/修改通知信息");
        return RespGenerator.returnOK(notificationService.modifyNotification(notificationVO));
    }

    @ApiOperation(value = "PC端发布、撤销通知信息")
    @PostMapping("/changeNotificationStatus")
    @MyLog(systemFunctionName = "维护通知", systemFunctionUrl = "/notificationController/changeNotificationStatus", userOperationType = 2, userOperationSummary = "PC端发布、撤销通知")
    public BaseResponse<String> changeNotificationStatus(@RequestBody ChangeNotificationStatusVO vo) {
        // 发布、撤销通知信息
        logger.info("PC端发布、撤销通知信息");
        notificationService.changeNotificationStatus(vo);
        return RespGenerator.returnOK("发布/撤销成功");
    }

    @ApiOperation("app端点击未读通知变为已读")
    @GetMapping("/modifyReadStatus")
    @MyLog(systemFunctionName = "维护通知", systemFunctionUrl = "/notificationController/modifyReadStatus", userOperationType = 2, userOperationSummary = "app端查看未读通知")
    public BaseResponse<String> modifyReadStatus(@RequestParam @ApiParam(value = "通知id",required = true) String notificationId){
        notificationService.modifyReadStatus(notificationId);
        return RespGenerator.returnOK("操作成功");
    }
}
